package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Trail;
import com.ruoyi.system.service.ITrailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆轨迹信息Controller
 * 
 * @author zbb
 * @date 2023-02-13
 */
@Controller
@RequestMapping("/trail/trail")
public class TrailController extends BaseController
{
    private String prefix = "trail/trail";

    @Autowired
    private ITrailService trailService;

    @RequiresPermissions("trail:trail:view")
    @GetMapping()
    public String trail()
    {
        return prefix + "/trail";
    }

    /**
     * 查询车辆轨迹信息列表
     */
    @RequiresPermissions("trail:trail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Trail trail)
    {
        startPage();
        List<Trail> list = trailService.selectTrailList(trail);
        return getDataTable(list);
    }

    /**
     * 导出车辆轨迹信息列表
     */
    @RequiresPermissions("trail:trail:export")
    @Log(title = "车辆轨迹信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Trail trail)
    {
        List<Trail> list = trailService.selectTrailList(trail);
        ExcelUtil<Trail> util = new ExcelUtil<Trail>(Trail.class);
        return util.exportExcel(list, "车辆轨迹信息数据");
    }

    /**
     * 新增车辆轨迹信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆轨迹信息
     */
    @RequiresPermissions("trail:trail:add")
    @Log(title = "车辆轨迹信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Trail trail)
    {
        return toAjax(trailService.insertTrail(trail));
    }

    /**
     * 修改车辆轨迹信息
     */
    @RequiresPermissions("trail:trail:edit")
    @GetMapping("/edit/{trailId}")
    public String edit(@PathVariable("trailId") Long trailId, ModelMap mmap)
    {
        Trail trail = trailService.selectTrailByTrailId(trailId);
        mmap.put("trail", trail);
        return prefix + "/edit";
    }

    /**
     * 车辆轨迹信息查看
     */
    @RequiresPermissions("trail:trail:edit")
    @GetMapping("/detail/{trailId}")
    public String detail(@PathVariable("trailId") Long trailId, ModelMap mmap)
    {
        Trail trail = trailService.selectTrailByTrailId(trailId);
        mmap.put("trail", trail);
            return prefix + "/detail";
    }

    /**
     * 修改保存车辆轨迹信息
     */
    @RequiresPermissions("trail:trail:edit")
    @Log(title = "车辆轨迹信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Trail trail)
    {
        return toAjax(trailService.updateTrail(trail));
    }

    /**
     * 删除车辆轨迹信息
     */
    @RequiresPermissions("trail:trail:remove")
    @Log(title = "车辆轨迹信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trailService.deleteTrailByTrailIds(ids));
    }
}
